local mysql = require "model.mysql"
local blacklist_model = {}

function blacklist_model.add(service_id, ip, description)
    description = ndk.set_var.set_quote_sql_str(description)
    local db = mysql.getDb()
    local res, err, _, _ = db:query("INSERT INTO agw_blacklist(service_id,ip,description)values(\'" .. service_id .. "\',\'" .. ip .. "\'," .. description .. ")", 10)
    db:set_keepalive(10000, 100)
    return res, err
end

function blacklist_model.delete(blacklist_id)
    local db = mysql.getDb()
    local res, err, _, _ = db:query("DELETE FROM agw_blacklist WHERE id=" .. blacklist_id, 10)
    db:set_keepalive(10000, 100)
    return res, err
end

function blacklist_model.getServiceBlacklist(service_id)
    local db = mysql.getDb()
    local blacklist, err, errno, sqlstate = db:query("SELECT * FROM agw_blacklist WHERE service_id=" .. service_id, 10)
    return blacklist, err
end

return blacklist_model
